package org.example.dianguanjia;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.http.ContentType;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ============================================================<br>
 * <p> ProjectName ：daochumysql </p>
 * <p> @author dongjianzhao </p>
 * <p> @date 2023/3/13 </p>
 * <p> @version ：1.0 </p>
 * ============================================================<br>
 * <p>
 * httputils
 * </p>
 * ============================================================<br>
 */
public class HttpUtils {

    public static String httpPost(String url,Map<String,Object> param,String cookie) {
        //链式构建请求
        String result2 = HttpRequest.post(url)
                //头信息，多个头信息多次调用此方法即可
                .header(Header.USER_AGENT, String.valueOf(ContentType.FORM_URLENCODED))
                .cookie(cookie)
                .body(JSON.toJSONString(param))
                //超时，毫秒
                .timeout(100000)
                .execute().body();
        return result2;
    }
    public static String httpPost2(String url, Map<String,Map<String,Object>> param,String cookie) {
        //链式构建请求
        String result2 = HttpRequest.post(url)
                //头信息，多个头信息多次调用此方法即可
                .header(Header.USER_AGENT, String.valueOf(ContentType.FORM_URLENCODED))
                .cookie(cookie)
                .body(JSON.toJSONString(param))
                //超时，毫秒
                .timeout(100000)
                .execute().body();
        return result2;
    }
    public static void main(String str[]) {
       /* for(int i=1;i<15;i++){
            List<Map<String, Object>> list = getKhListMaps(i);
            list.forEach(f->{
                String custId= (String) f.get("custId");
                String custNo= (String) f.get("custNo");
                // dqlxr_f(custId);
                khjbxx_f(custId);
            });
        }*/
    }

  /*  public JSONObject sendPost(String url, LoginSsoReq req){
        HttpResponse httpResponse = null;
        try {
            JSONObject json=new JSONObject();
            json.put("client_id",req.getClientId());
            json.put("grant_type",req.getGrantType());
            json.put("code",req.getCode());
            json.put("remote_ip",req.getRemoteIp());
            json.put("redirect_uri",req.getRedirectUri());
            // 设置请求头
            Map<String, String > heads = new HashMap<>();
            heads.put("Content-Type", "application/json;charset=UTF-8");
            httpResponse =  HttpRequest.post(url) // url
                    .headerMap(heads, false) // 请求头设置
                    .body(json.toJSONString()) // json参数
                    .timeout(5 * 60 * 1000) // 超时
                    .execute(); // 请求
            System.out.println("获取返回服务器的状态码：----- " + httpResponse.getStatus() );
            if(httpResponse.getStatus() == 200){
                //成功后响应数据
                String result = httpResponse.body();
                JSONObject jsonResult = JSONObject.parseObject(result);
                System.out.println("接口返回数据："+jsonResult.toString());
                return jsonResult;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally{
            try {
                //释放连接
                if(httpResponse != null){
                    httpResponse.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return new JSONObject();
    }*/

}